<?php
/**
 * Created by PhpStorm.
 * User: locove
 * Date: 14-8-23
 * Time: 上午10:53
 */
class Temporary
{
    /**
     * 对单个采购单号进行查询的时候
     */
    public static function single_select($purchaseorder_id)
    {
        $status_array = array(10,20,40,50,60,65,70);//有效采购单明细状态
        $count_all = DB::select(array(DB::expr('count(id)'),'count_all'))
            ->from('purchaseorder_details')
            ->where('purchaseorder_id','=',$purchaseorder_id)
            ->where('status','in',$status_array)
            ->execute('newerp')
            ->current();
        //已经完成的多少个
        $count = DB::select(array(DB::expr('count(id)'),'count'))
            ->from('purchaseorder_details')
            ->where('purchaseorder_id','=',$purchaseorder_id)
            ->where('status','=',70)
            ->execute('newerp')
            ->current();
        //采购单上面的明细全部已经入库，则采购单也入库
        if($count_all['count_all']!=0){
            if($count['count'] >= $count_all['count_all'])
            {
                DB::update('purchaseorders')
                    ->set(array('status'=>70))
                    ->where('id','=',$purchaseorder_id)
                    ->execute('newerp');
            }
        }else{
    		//该采购单状态为90
        	$count_all = DB::select(array(DB::expr('count(id)'),'count_all'))
            ->from('purchaseorder_details')
            ->where('purchaseorder_id','=',$purchaseorder_id)
            ->where('status','!=',100)
            ->execute('newerp')
            ->current();
            
	        if($count_all['count_all']>0){
                DB::update('purchaseorders')
                    ->set(array('status'=>90))
                    ->where('id','=',$purchaseorder_id)
                    ->execute('newerp');
	        }
        }
    }
}




